<?php

namespace Admin\Controller;

use Think\Controller;

class CommonController extends Controller
{
    public function _initialize()
    {
        $this->check_admin_login();
    }

    /*
     * 跨入口打开HOME详细页
     */
    public function view()
    {
        $url_model = C('URL_MODEL');
        if ($url_model <> '0' && $url_model <> '1') {
            header("Content-type: text/html; charset=utf-8");
            exit("当前URL_MODEL设置为{$url_model}，不支持此跳转！");
        }
        $url = ytata_get_url();
        $url = str_replace("admin.php", "", $url);
        header("Location: {$url}");
    }

    /**
     * 检查是否管理员登录
     *
     * 如果不是则跳转至后台登录页面
     */
    private function check_admin_login()
    {
        $user = D('User');
        if (!$user->is_admin_login()) {
            exit('<script type="text/javascript">top.location="' . RU('/login/login') . '";</script>');
        }
    }
}